#include "widget.h"
#include "ui_widget.h"

#include <QPushButton>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QPushButton* btnAdd = new QPushButton(this);
    QPushButton* btnSub = new QPushButton(this);

    btnAdd->move(100,150);
    btnSub->move(350,150);

    btnAdd->setText("增加透明度");
    btnSub->setText("降低透明度");

    connect(btnAdd, &QPushButton::clicked, this, &Widget::addOpacitySlots);
    connect(btnSub, &QPushButton::clicked, this, &Widget::subOpacitySlots);


}

Widget::~Widget()
{
    delete ui;
}

void Widget::addOpacitySlots()
{
    float cur_opacity = this->windowOpacity();
    if(cur_opacity > 1.0)
    {
        return;
    }

    qDebug() << cur_opacity;

    cur_opacity -= 0.1;

    this->setWindowOpacity(cur_opacity);

}


void Widget::subOpacitySlots()
{
    float cur_opacity = this->windowOpacity();
    if(cur_opacity < 0.0)
    {
        return;
    }

    qDebug() << cur_opacity;

    cur_opacity += 0.1;

    this->setWindowOpacity(cur_opacity);
}
